package application;

import application.dao.DBService;
import application.dao.entity.Manager;
import application.dao.entity.User;
import com.sun.org.apache.xml.internal.security.Init;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;

import java.net.URL;
import java.util.ResourceBundle;

public class Athlete_main_controller extends BaseController implements Initializable {

    public javafx.stage.Stage stage;
    public Label showUserName;
    @FXML
    public Label showRealName;
    @FXML
    public Label showIdcard;
    @FXML
    public Label showMobile;
    @FXML
    private Menu menu_enroll;

    @FXML
    private Menu menu_main;

    @FXML
    private MenuItem menu_informations_announcements;

    @FXML
    private MenuItem menu_informations_news;

    @FXML
    private Menu menu_person;

    @FXML
    private Menu menu_informations;

    @FXML
    private Menu menu_scores;

    @FXML
    void ff8f8f(ActionEvent event) {

    }

    @FXML
    void ffc88f(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_main(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_person(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_enroll(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_scores(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_informations(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_informations_announcements(ActionEvent event) {
        Athlete_announcement_show app = new Athlete_announcement_show();
        BaseUtil.goPage(app, app.stage);
    }

    @FXML
    void onCheckMenu_informations_news(ActionEvent event) {
        Athlete_news_show app = new Athlete_news_show();
        BaseUtil.goPage(app, app.stage);
    }


    @Override
    public void init() {
        Label main = new Label("首页");
        Label person = new Label("个人信息");
        Label scores = new Label("赛事报名");
        Label info = new Label("成绩查询");
        main.setOnMouseClicked(event -> {
            Manager_main_show application = new Manager_main_show();
            BaseUtil.hideGoPage(stage, application, application.stage);
        });
        person.setOnMouseClicked(event -> {
            Athlete_personal_information_show application = new Athlete_personal_information_show();
            BaseUtil.hideGoPage(stage, application, application.stage);
        });
        scores.setOnMouseClicked(event -> {
            User loginUser = Global.loginUser;
            if (null == DBService.queryEnrollUser(loginUser.getUserName(), null)) {
                Athlete_enroll_show application = new Athlete_enroll_show();
                BaseUtil.hideGoPage(stage, application, application.stage);
            } else {
                Athlete_enroll_already_show application = new Athlete_enroll_already_show();
                BaseUtil.hideGoPage(stage, application, application.stage);
            }
        });
        info.setOnMouseClicked(event -> {
            Athlete_scores_show application = new Athlete_scores_show();
            BaseUtil.hideGoPage(stage, application, application.stage);
        });

        //将标签设置到menu的graphic属性当中
        menu_main.setGraphic(main);
        menu_person.setGraphic(person);
        menu_scores.setGraphic(scores);
        menu_enroll.setGraphic(info);
        initShow();
    }

    private void initShow() {
        User loginUser = Global.loginUser;
        showIdcard.setText(loginUser.getIdCard());
        showUserName.setText(loginUser.getUserName());
        showMobile.setText(loginUser.getTelNumber());
        showRealName.setText(loginUser.getRealName());

    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        init();
    }
}
